import { EnumSchema } from '#/common';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 设备状态枚举 */
export enum DeviceStatusEnum {
  /** 未知 */
  Unknown = 0,
  /** 良好 */
  Good = 1,
  /** 部分良好 */
  PartGood = 2,
  /** 损坏 */
  Bad = 99,
}

/** 设备状态实体 */
export class DeviceStatusEntity {
  /** 设备状态 */
  Status: DeviceStatusEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(status: DeviceStatusEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.Status = status;
    this.Color = color;
    switch (status) {
      case DeviceStatusEnum.Unknown:
        // this.Display = '未知';
        this.Display = t('iot.enum.deviceStatus.unknown');
        this.Color = this.Color ? this.Color : PresetColorEnum.Default;
        break;
      case DeviceStatusEnum.Good:
        // this.Display = '良好';
        this.Display = t('iot.enum.deviceStatus.good');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DeviceStatusEnum.PartGood:
        // this.Display = '部分良好';
        this.Display = t('iot.enum.deviceStatus.partGood');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case DeviceStatusEnum.Bad:
        // this.Display = '损坏';
        this.Display = t('iot.enum.deviceStatus.bad');
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
    }
  }
}

//#region 获取设备状态枚举架构
/**
 * 获取设备状态枚举架构
 */
export function getDeviceStatusEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DeviceStatusEntity[] = [
    new DeviceStatusEntity(DeviceStatusEnum.Unknown),
    new DeviceStatusEntity(DeviceStatusEnum.Good),
    new DeviceStatusEntity(DeviceStatusEnum.PartGood),
    new DeviceStatusEntity(DeviceStatusEnum.Bad),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.Status as number,
      label: item.Display,
      value: item.Status as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
